package com.wechat.back.controller;

import com.wechat.back.anno.OptLog;
import com.wechat.back.pojo.articles.Category;
import com.wechat.back.pojo.tools.Result;
import com.wechat.back.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @OptLog(optModule = "文章标签模块",optType = "添加", optDesc = "添加分类")
    @PostMapping
    public Result add(@RequestBody @Validated(Category.Add.class) Category category){
        categoryService.add(category);
        return Result.success();
    }

    @GetMapping
    public Result<List<Category>> list(){
        List<Category> cs = categoryService.list();
        return Result.success(cs);
    }

    // 查询所有
    @GetMapping("/list")
    public Result<List<Category>> allList(){
        List<Category> cs = categoryService.allList();
        return Result.success(cs);
    }
    // 查询通过审核的分类
    @GetMapping("/allowList")
    public Result<List<Category>> allowList(){
        List<Category> cs = categoryService.allowList();
        return Result.success(cs);
    }
    // 查询未通过审核的分类
    @GetMapping("/disallowList")
    public Result<List<Category>> disallowList(){
        List<Category> cs = categoryService.disallowList();
        return Result.success(cs);
    }
    // 查询所有待审核的分类
    @GetMapping("inspectList")
    public Result<List<Category>> inspectList(){
        List<Category> cs = categoryService.inspectList();
        return Result.success(cs);
    }

    @GetMapping("/detail")
    public Result<Category> detail(Integer id){
        Category c = categoryService.findById(id);
        return Result.success(c);
    }

    @OptLog(optModule = "文章标签模块",optType = "修改", optDesc = "修改分类")
    @PutMapping
    public Result update(@RequestBody @Validated(Category.Update.class) Category category){
        categoryService.update(category);
        return Result.success();
    }

    @OptLog(optModule = "文章标签模块",optType = "删除", optDesc = "删除分类")
    @DeleteMapping
    public Result delete(Integer id){
        categoryService.deleteById(id);
        return Result.success();
    }
}
